//初始化单页view
var viewApi = mui('#app').view({
    defaultPage: '#setting'
});
//初始化单页的区域滚动
mui('.mui-scroll-wrapper').scroll();

var view = viewApi.view;
(function($) {
    //处理view的后退与webview后退
    var oldBack = $.back;
    $.back = function() {
        if (viewApi.canBack()) { //如果view可以后退，则执行view的后退
            viewApi.back();
        } else { //执行webview后退
            oldBack();
        }
    };
    //监听页面切换事件方案1,通过view元素监听所有页面切换事件，目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
    //第一个参数为事件名称，第二个参数为事件回调，其中e.detail.page为当前页面的html对象
    view.addEventListener('pageBeforeShow', function(e) {
        //				console.log(e.detail.page.id + ' beforeShow');
    });
    view.addEventListener('pageShow', function(e) {
        //				console.log(e.detail.page.id + ' show');
    });
    view.addEventListener('pageBeforeBack', function(e) {
        //				console.log(e.detail.page.id + ' beforeBack');
    });
    view.addEventListener('pageBack', function(e) {
        //				console.log(e.detail.page.id + ' back');
    });
})(mui);


//步骤1:触发点击事件
function next() {
    var btn = document.getElementById("toNext");
    btn.addEventListener("tap", function () {
        console.log("tap toNext trigger");
    });
    mui.trigger(btn,'tap');
}

// 60s倒计时
var wait=60;
var flag =true;
function time(o) {
    if (wait == 0) {
        o.removeAttribute("disabled");
        o.innerHTML="发送验证码";
        wait = 60;
        flag=true;
    } else {
        flag = false;
        o.setAttribute("disabled", true);
        o.innerHTML="重新发送(" + wait + ")";
        wait--;
        setTimeout(function () {
                time(o)
            },
            1000)
    }
}


mui.ready(function () {

    // 倒计时
    mui(".mui-input-row").on('tap', "#send", function () {
        if(flag){
            time(this);
            console.log("11")
        }else{

            console.log("22")
        }
    })

    // 步骤1:下一步
    mui(".mui-button-df").on('tap', "#next", function () {
        console.log("tap event 112");
        // 数据
        var realname = mui("#realname")[0].value;
        var phone = mui("#phone")[0].value;
        var idCard = mui("#idCard")[0].value;
        var bankNo = mui("#bankNo")[0].value;
        var data = {
            realname:realname,
            phone:phone,
            idCard:idCard,
            bankNo:bankNo,
        }
        console.log('data',data)

        next()
    })

    // 步骤2:提交
    mui(".mui-button-df").on("tap","#submit",function () {
        // 数据
        var newphone = mui("#newphone")[0].value;
        var phonecode = mui("#phoneCode")[0].value;
        var data = {
            newphone:newphone,
            phonecode:phonecode,
        }
        if(newphone.length !=11){
            mui.alert("请输入新的手机号"); return;
        }
        if(!phonecode){
            mui.alert("请输入验证码"); return;
        }

        console.log('data',data)
        // 执行提交
        // request("bind.do",data,function (res) {
        // })
    })

})



